﻿using Oracle.ManagedDataAccess.Client;
using Simple.Services.System.Jobs;

public class TaskManagerController : ControllerBase
{
    private readonly TaskManagerService _timerTask;

    public TaskManagerController(TaskManagerService timerTask)
    {
        _timerTask = timerTask;
        _timerTask.Initialize(async () =>
        {
            TaskManager.CleanAllTasks();
            OracleConnection.ClearAllPools();
        });
    }

    // GET: timer/start
    [HttpGet("start")]
    public IActionResult StartTimer()
    {
        try
        {
            _timerTask.Start();
            return Ok("Timer started.");
        }
        catch (Exception ex)
        {
            return StatusCode(500, $"Error starting timer: {ex.Message}");
        }
    }

    // GET: timer/stop
    [HttpGet("stop")]
    public IActionResult StopTimer()
    {
        try
        {
            _timerTask.Stop();
            return Ok("Timer stopped.");
        }
        catch (Exception ex)
        {
            return StatusCode(500, $"Error stopping timer: {ex.Message}");
        }
    }
}
